<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>商品名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="goodsName" name="goodsName"  class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="phone" class="layui-form-label">
                            <span class="x-red">*</span>商品价格</label>
                        <div class="layui-input-inline">
                            <input type="text" id="price" name="price"  class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>商品库存</label>
                        <div class="layui-input-inline">
                            <input type="text" id="stock" name="stock"  class="layui-input"></div>
                    </div>
					<div class="layui-form-item">
					    <label for="username" class="layui-form-label">
					        <span class="x-red">*</span>创建时间</label>
					    <div class="layui-input-inline">
					        <input type="date" id="createTime" name="createTime" class="layui-input"></div>
					</div>
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>商品分类</label>
                        <div class="layui-input-inline">
                            <select id="categoryId" name="categoryId" class="valid">
                             </select> 
                        </div>
                    </div>
					<div class="layui-form-item">
							<label for="L_repass" class="layui-form-label"></label>
							<button class="layui-btn" lay-filter="add" lay-submit="">增加商品</button>
					</div>
        </form>
        </div>
        </div>
        <script>
			layui.use(['form','laydate'],function(){
				
				var form = layui.form;
				var $ = layui.jquery;
				var laydate = layui.laydate;
				$.getJSON("http://localhost:8080/getCategoryList",function(d){
					console.log("dddd====",d);
					var r = d.data;
					var str ="";
					for(var i =0;i<r.length;i++){
						str +="<option value=\""+r[i].categoryId+"\">"+r[i].categoryName+"</option>"
						
					}
					$("#categoryId").html(str);
					//渲染页面
					form.render("select");
				});
				
				form.on('submit(add)',function(obj){
					console.log("表单触发事件",obj);
					
					$.post("http://localhost:8080/addGoods",obj.field,function(res){
						console.log("res",res.code);					
						if(res.code!=200){
							layer.msg(res.msg);
						}
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
						window.parent.location.reload();
					},"json");
					return false;
					
				})
				
				
				
				
				
				
				
			})
			
			
		</script>
    </body>

</html>